import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;

/**
 * 使用ArrayList集合统计每一个元素出现次数
 */
public class homework01 {
    public static void main(String[] args) {
     String[] array = {"a","c","b","d","e","a","b"};
        HashSet<String> str = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            str.add(array[i]);
        }
        ArrayList<String> list = new ArrayList<>(str);
        Collections.sort(list);
        for (int i = 0; i < list.size(); i++) {
            int count = 0;
            for (int j = 0; j < array.length; j++) {
                if (list.get(i).equals(array[j])){
                    count++;
                }
            }
            System.out.println(list.get(i)+":"+count+"次");
        }
    }
}
